home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
combin.arc
/
COMBIN.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1985-08-24
|
9KB
|
181 lines
{$g512,P512,D-}
{ This program will take a Turbo main line program and create a file that
contains all of the code for the program, main line plus include files.
The program uses I/O re-direction and requires TP3. A sample command line
would be like the following :
combine < main.pas > allone.pas
To create a file called 'allone.pas' that contains all of the code
for main.pas plus all of the include files.
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
Path names are not supported in the include directives for this
program.
}
program combine(input,output);
type
FCB_Layout = record
Drive : byte;
FileName : Array[1..8] of char;
FileExt : Array[1..3] of char;
CurBlock : integer;
RecSize : integer;
FSizeLow : integer;
FSizeHigh : integer;
CreateDate : integer;
CreateTime : integer;
Flags : byte;
DiskAddr1st : integer;
DiskAddrLst : integer;
LastAccess : Array [1..3] of byte;
NextRecord : byte;
RelRecLow : integer;
RelRecHigh : integer;
end;
Registers = Record Case Integer Of
1: (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags: Integer);
2: (al,ah,bl,bh,cl,ch,dl,dh: Byte);
End;
Alpha = String[255];
var
MBuffer,
Buffer : Alpha;
i : integer;
Ok : boolean;
F : Alpha;
{*********************************************************************}
{ Read the Include file and output it, every byte }
procedure ReadInclude(F:Alpha;var Ok:boolean);
var
Ch : char;
IFile : Text;
begin
Assign(IFile,F); { Assign the include file }
{$I-} Reset(IFile) {$I+}; { try to open the file }
Ok:=(IOresult=0); { was there any problem }
if Ok then { if not then lets go to work }
begin { start the ball rolling }
writeln('{*Include File ',F,' ***** START *****}');
while not Eof(IFile) do { loop through the entire file }
begin { till we get to the end }
read(IFile,Ch); { read a character, ( could be better)}
write(Ch); { write a character, How boring }
end; { Loop one, Branch two }
writeln; { make sure your at the left margin }
writeln('{*Include File End ',F,' ***** END *****}');
close(IFile); { close the file }
end; { end of 'file found code' }
end;
{ ************************************************************************
Take a string and scan it for a file name, using a pre-MSDOS 2 system
call. Since there is not a call like this that supports paths the
file names will be minus the path names.
}
function FileNameScan(S:Alpha):Alpha;
var
T : FCB_Layout;
i : integer;
Regs : Registers;
k : integer;
begin
S:=S+Chr(0); { MSDOS requires ASCIIZ strings }
with Regs do { set up the registers for the call }
begin { using the registers }
ah:=$29; { function 29 hex }
al:=0; { see manual ( too complex for here) }
DS:=Seg(S); { pass segment address of string }
SI:=Ofs(S)+1; { offset , skip length byte }
ES:=Seg(T); { pas address (segment) of FCB }
DI:=Ofs(T); { pass the offset }
end; { all set for call }
with T do { let ready the FCB for the call }
begin { ok, lets do it ..... }
for i:=1 to 8 do { clear file name }
FileName[i]:=' '; { to blanks }
for i:=1 to 3 do { clear file extention }
FileExt[i]:=' '; { to blanks }
end; { FCB ready }
MsDos(Regs); { call DOS }
with T do { ok, lets look at the FCB }
begin { and pull out the info }
k:=0; { string length is zero }
for i:=1 to 8 do { loop through the file name }
if not(FileName[i]=' ') then { blank ??? }
begin { no, good then lets grab the char }
k:=k+1; { one more into the string }
S[k]:=FileName[i]; { MOVE IT }
end; { continue ......... }
k:=k+1; { count the period }
S[k]:='.'; { and put it into the string }
for i:=1 to 3 do { now move the extention }
if not(FileExt[i]=' ') then { blank ???? }
begin { no, good let move it }
k:=k+1; { count the sucker }
S[k]:=FileExt[i]; { move it ... march .. left .. right }
end; { one more time ... }
S[0]:=Chr(k); { set string length }
end;
FileNameScan:=S; { return our stuff }
end;
{ function to convert lower case variable names to uppercase for comparison
since variable names are case insensative. }
function UpStr(s:alpha):alpha;
var
i : integer;
begin
for i:=1 to length(s) do
s[i]:=UpCase(s[i]);
UpStr:=s;
end;
{ ---------------------------------------------------------------------
Main line code, read a line from the file and check for an
include directive. If found the put the text from the include
file into the output file and then continue. But do not
move the include file directive into the output file.
}
begin
while not Eof(input) do { while there is more input do }
begin { loop .......... }
Readln(Buffer); { read a line }
MBuffer:=UpStr(Buffer); { convert to upper case }
i:=Pos('$I',MBuffer); { look for directive }
if (MBuffer[i+2]='+') or { was it I+ }
(MBuffer[i+2]='-') then i:=0; { was it I-, if so don't do anything }
If not(i=0) then { ok, was it for real }
begin { yes, lets get the file name and run }
F:=FileNameScan(copy(MBuffer,i+2,Length(MBuffer)));
ReadInclude(F,Ok); { try to process the include file }
if not Ok then { was it there ???? }
begin { no ... sob ... sob }
writeln('{ Include File ',F,' NOT Found }');
writeln('Include file ',F,' , not found.');
end; { output the bad new, force compile error }
end { ok done for include directive }
else { otherwise ......... }
writeln(Buffer); { output the line }
end;
end.